<template>
  <div class="deliver-goods">
    <header>
      <div class="order-box">
        <div class="order-no">订单号：{{ formData.order_no }}</div>
      </div>
      <div class="name">
        <div>
          用户姓名：{{ userAddress.name }}<span class="phone">用户电话：{{ userAddress.tel }}</span>
        </div>
        <div>地址：{{ userAddress.province }} {{ userAddress.city }} {{ userAddress.area }} {{ userAddress.address }}</div>
      </div>
    </header>
    <div class="goods">
      <div> 产品：{{formData.product_name}} {{formData.sku_name}} </div>
      <div class="img-box"> 图片：<el-image :src="$imageFull(ruleForm.sku.image)" style="height: 80px" /> </div>
    </div>

    <el-form :model="ruleForm" ref="ruleForm" label-width="100px" class="demo-ruleForm">

      <div class="form-box">
        <el-form-item label="售后单号">
          <el-input v-model="ruleForm.after_sales_no" readonly></el-input>
        </el-form-item>
        <el-form-item label="申请类型">
          <el-tag
            :type="SERVICE_APPLY_FOR_TYPE[String(ruleForm.apply_type)] && SERVICE_APPLY_FOR_TYPE[String(ruleForm.apply_type)].type"
            disable-transitions>
            <i :class="SERVICE_APPLY_FOR_TYPE[String(ruleForm.apply_type)] && SERVICE_APPLY_FOR_TYPE[String(ruleForm.apply_type)].icon"
              style="margin-right: 4px" />
            {{ SERVICE_APPLY_FOR_TYPE[String(ruleForm.apply_type)] ? SERVICE_APPLY_FOR_TYPE[String(ruleForm.apply_type)].text : '未知状态' }}
          </el-tag>
        </el-form-item>

        <el-form-item label="申请原因">
          <el-input v-model="ruleForm.apply_reason" readonly></el-input>
        </el-form-item>

        <el-form-item label="退款金额">
          <el-input v-model="ruleForm.refund_amount" readonly></el-input>
        </el-form-item>


        <el-divider></el-divider>

        <el-form-item label="审核原因" prop="reason">
          <el-input type="textarea" :autosize="{ minRows: 2, maxRows: 4}" placeholder="请输入审核原因" v-model="reason">
          </el-input>
        </el-form-item>
        <div class="def-bt-box">
          <el-button type="primary" @click="submitData(1)" class="bt-fix"> 通过 </el-button>
          <el-button type="danger" @click="submitData(2)" class="bt-fix"> 拒绝 </el-button>
        </div>

      </div>
    </el-form>

  </div>
</template>

<script>
  import {
    SERVICE_APPLY_FOR_TYPE
  } from '@/constants/statusMap';
  export default {
    name: "ServiceOrderAfterSales",
    props: {
      formData: {
        type: Object,
        required: true
      },
    },
    data() {
      return {
        SERVICE_APPLY_FOR_TYPE,
        userAddress:{},
        reason: '',
        ruleForm: {
          sku:{
            image:'',
          },
          after_sales_no: '',
          apply_type: 0,

        },
      };
    },
    mounted() {
      this.ServiceOrderAfterSales();
      this.userAddress = this.formData.address;

    },
    methods: {
      submitData(val) {
        let postData = {};
        if(val===2){
          if(!this.reason || this.reason.length < 5){
            this.$message.error('拒绝售后必段填写拒绝的理由,并且不得少于5个字')
            return false;
          }
        }
        postData.status = val;
        postData.reason = this.reason;
        postData.id = this.ruleForm.id;
        this.$emit('afterSales', postData)
      },

      ServiceOrderAfterSales() {
        this.$httpRequest.get('/ServiceAfterSales/info', {
          order_id: this.formData.id
        }).then(result => {

          this.ruleForm = result.data

        }).catch(e => {
          this.$message.error(e.message)
        });
      }

    },
  };
</script>

<style scoped lang="scss">
  header {
    background-color: #fdf6ec;
    color: #e6a23c;
    padding: 30px;
    box-sizing: border-box;
  }

  .goods{
    padding: 30px;
    box-sizing: border-box;
    font-size: 16px;
  }

  .deliver-goods {}

  .demo-ruleForm{
    background-color: #fcfcfc;
  }

  .form-box {
    padding: 30px;
    box-sizing: border-box;
  }

  .order-no {
    font-size: 18px;
    padding-bottom: 10px;
  }

  .name {
    font-size: 16px;
    line-height: 24px;
  }

  .def-bt-box {
    padding: 30px;
  }

  .phone {
    padding-left: 20px;
  }

  .img-box{
    margin-top: 20px;
    display: flex;
    align-items:center;
  }
</style>
